/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cip.esymons.tesoreria.beans;

import java.util.List;
import javax.faces.model.SelectItem;
import org.cip.esymons.general.be.Rubro;
import org.cip.esymons.tesoreria.bc.RubroTesoreriaDelegate;

/**
 *
 * @author Ingrid Capuñay
 */
public class RubroTesoreriaController {

    private RubroTesoreriaDelegate delegado;

    public RubroTesoreriaController() {
        delegado = new RubroTesoreriaDelegate();
    }

    public Rubro buscarRubroPorCodigo(Integer cod) {
        try {
            return delegado.buscarUnRubro(cod);
        } catch (Exception ex) {
            return null;
        }
    }

    public SelectItem[] getRubroItem() {
        try {
            List<Rubro> lr = delegado.listarTodosRubros();
            SelectItem[] select = new SelectItem[lr.size() + 1];
            select[0]= new SelectItem(new Rubro(0, "Todos"), "Todos");
            int i = 1;
            for (Rubro ru : lr) {
                SelectItem item = new SelectItem(ru, ru.getRubDescripcion());                
                select[i++] = item;
            }

            return select;

        } catch (Exception ex) {
            SelectItem[] select = new SelectItem[1];
            SelectItem item = new SelectItem(null, "No existen Rubros");
            select[0] = item;
            return select;
        }
    }

    public SelectItem[] getRubroItem2() {
        try {
            List<Rubro> lr2 = delegado.listarTodosRubros();
            SelectItem[] select = new SelectItem[lr2.size() + 1];
            select[0]= new SelectItem(new Rubro(0, "Ninguno"), "Ninguno");
            int i2 = 1;
            for (Rubro ru2 : lr2) {
                SelectItem item = new SelectItem(ru2, ru2.getRubDescripcion());
                select[i2++] = item;
            }

            return select;

        } catch (Exception ex) {
            SelectItem[] select = new SelectItem[1];
            SelectItem item = new SelectItem(null, "No existen Rubros");
            select[0] = item;
            return select;
        }
    }
}
